<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">   
<title>Insert title here</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>OA人脸识别员工管理系统</title>
<link rel="stylesheet" href="./resource/layui/css/layui.css">
<script src="./resource/js/jquery-2.0.3.js"></script>
</head>
<body>
	<body class="layui-layout-body">
	<div class="layui-layout layui-layout-admin">
		<div class="layui-header">
			<div class="layui-logo">
				<img src="./resource/image/logo.png"
					style="width: 200px; height: 58px;">
			</div>
			<!-- 头部区域（可配合layui已有的水平导航） -->
			<ul class="layui-nav layui-layout-left">
				<iframe id="tianqi" allowtransparency="true" frameborder="0"
					width="410" height="60" scrolling="no"
					src="//tianqi.2345.com/plugin/widget/index.htm?s=2&z=3&t=1&v=2&d=2&bd=0&k=&f=ffffff&ltf=009944&htf=cc0000&q=0&e=1&a=1&c=59134&w=410&h=60&align=center"></iframe>
			</ul>
			<ul class="layui-nav layui-layout-right">
				<li class="layui-nav-item"><a href="javascript:;"> <img
						src="http://t.cn/RCzsdCq" class="layui-nav-img">
						${sessionScope.emp.empname}
				</a>
					<dl class="layui-nav-child">
						<dd>
							<a href="UserInfo.jsp">修改个人信息</a>
						</dd>
					</dl></li>
				<li class="layui-nav-item"><a href="login.jsp" >退出</a></li>
			</ul>
		</div>


		<div class="layui-side layui-bg-black">
			<div class="layui-side-scroll">
				<!-- 左侧导航区域（可配合layui已有的垂直导航） -->
				<ul class="layui-nav layui-nav-tree" lay-shrink="all"
					lay-filter="test">
					<li class="layui-nav-item"><a class="" href="javascript:;"><i
							class="layui-icon"> &#xe637; </i>考勤</a>
						<dl class="layui-nav-child">
							<dd>
								<a href="punch.jsp">打卡</a>
							</dd>			
                    <c:if test="${sessionScope.emp.position!='员工'}">
							<dd>
								<a href="Hrpattence.jsp">员工考勤查看</a>
							</dd>
							</c:if>
								<dd>
									<a href="MyselfPattence.jsp">自我考勤查看</a>
								</dd>
						</dl></li>
					<li class="layui-nav-item layui-nav-itemed"><a href="javascript:;"><i
							class="layui-icon">&#xe613; </i>请假管理</a>
						<dl class="layui-nav-child">
								<a href="leavetest.jsp" class="layui-this"></i>请假申请</a>
							<c:if test="${sessionScope.emp.position!='员工'&&sessionScope.emp.position!='人事'}">
							<dd>
								<a href="LeaveList.jsp">请假审批</a>
							</dd>
							</c:if>
								<c:if test="${sessionScope.emp.position!='经理'}">
							<dd>
								<a href="LeaveMsg.jsp">请假信息查看</a>
							</dd>
							</c:if>
						</dl></li>
					<li class="layui-nav-item"><a
						href="javascript:;"><i class="layui-icon">&#xe716; </i>管理</a>
						<dl class="layui-nav-child">
							<c:if test="${sessionScope.emp.position!='员工'&&sessionScope.emp.position!='经理'}">
								<dd>
									<a href="GetEmps.jsp" >员工管理</a>
								</dd>
							</c:if>
							<c:if test="${sessionScope.emp.position!='员工'}">
								<dd>
									<a href="GetDepts.jsp">部门管理</a>
								</dd>
							</c:if>
							<dd>
								<a href="UserInfo.jsp">个人信息管理</a>
							</dd>
						</dl></li>
					<li class="layui-nav-item"><a href="Note.jsp">公告</a></li>
				</ul>
			</div>
		</div>
				<div class="layui-body">
					<!-- 内容主体区域 -->
					<div class="layui-container">
						<div class="layui-row">
							<div class="layui-col-md7 layui-col-md-offset">
								<h2 style="padding: 15px;">请假申请</h2>
								<!-- 表单 -->
								<form class="layui-form" id="leave" action="LeaveServlet" method="get">
									<div class="layui-form-item">
										<label class="layui-form-label">申请人ID</label>
										<div class="layui-input-inline" id="agent" name="agent">
											<input type="text" name="empid" class="layui-input" value="${sessionScope.emp.empid}" readonly="readonly" style="border: none;">
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">申请人员</label>
										<div class="layui-input-inline" id="agent" name="agent">
											<input  type="text" name="empname" class="layui-input" value="${sessionScope.emp.empname}" readonly="readonly" style="border: none;">
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">请假类型</label>
										<div class="layui-input-block" id="leave_type" name="leavetype">
											<input type="radio" name="leavetype" value="年假" title="年假" checked="checked">
											<input type="radio" name="leavetype" value="病假" title="病假">
											<input type="radio" name="leavetype" value="产假" title="产假">
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">请假时间</label>
										<div class="layui-input-block">
											<div class="layui-inline">
												<div class="layui-input-inline">
													<input type="text" name="starttime" class="layui-input laydate" id="start_time" placeholder="开始时间">
												</div>
											</div>
											<div class="layui-inline">
												<div class="layui-input-inline">
													<input type="text" name="endtime" class="layui-input laydate" id="end_time" placeholder="结束时间">
												</div>
											</div>
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">性别选择</label>
										<div class="layui-input-block">
											<input type="radio" name="sex" value="男" title="男">
											<input type="radio" name="sex" value="女" title="女">
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">审批人名字</label>
										<div class="layui-input-block">
											<div class="layui-input-inline">
												<input type="text" hidden="hidden" id="apprid" name="apprid" value="3"> 
												<input type="text" class="layui-input" name="managepname" placeholder="审批人ID" id="managepname" readonly="readonly">
											</div>
										</div>
									</div>
									<div class="layui-form-item layui-form-text">
										<label class="layui-form-label">请假原因</label>
										<div class="layui-input-block">
											<textarea name="leavecomment" placeholder="请输入请假申请原因" class="layui-textarea"></textarea>
										</div>
									</div>
									<div class="layui-form-item">
										<div class="layui-input-block">
											<button type="button" class="layui-btn" onclick="leave()">立即提交</button>
											<button type="reset" class="layui-btn layui-btn-primary">重置</button>
											<span id="msg"></span>
											<input type="text" name="op" value="CreatLeave" hidden="hidden">
											<% 
												session.setAttribute("token", System.nanoTime()+"");
											%>
											<input type="text" name="token" value="${sessionScope.token }" hidden="hidden">
										</div>
										
									</div>
								</form>
								<!-- 表单结束 -->
							</div>
							<div class="layui-col-md3 layui-col-md-offset2">
								<h2 style="padding: 15px;">日历</h2>
								<div class="layui-inline" id="calendar">
								</div>
							</div>
						</div>
					</div>
				</div>

				<div class="layui-footer">
					<!-- 底部固定区域 -->
					© 中软 - JAVA二阶段项目 - 基于人脸识别的考勤系统 by TeamWork_XM
				</div>
			</div>
			<script src="./resource/layui/layui.js"></script>
			<script>
			  $.ajax({
				  type: "get",
				  url: "EmpServlet?op=GetEmpName",
				  dataType: "json",
				  data:{
					  empid:"${sessionScope.emp.empid}",
					  
				  },
				  success:function(msg){
					  console.log(msg);
					  $("#managepname").val(msg.empname);
					  $("#apprid").val(msg.empid);
				  }
				  
				  
			  });
				//请假开始日期时间范围
				layui.use('laydate', function() {
					var laydate = layui.laydate;
					//var nowTime=new Date();
					//执行一个laydate实例
					laydate.render({
						elem: '#start_time', //指定元素
						type: 'datetime', //时间日期选择器
						theme: '#0DB6F5', //颜色选取
						calendar: true, //节日显示
						btns: ['confirm'],
						min: -7,
						max: 7, //当前时间
					});
				});
				//日历表
				layui.use('laydate', function() {
					var laydate = layui.laydate;
					//var nowTime=new Date();
					//执行一个laydate实例
					laydate.render({
						elem: '#calendar', //指定元素
						type: 'date', //时间日期选择器
						show: true,
						theme: 'grid',
						theme: '#0DB6F5',
						position: 'static',
						calendar: true, //节日显示
						btns: ['now'],
					});
				});
				//请假结束日期时间范围
				layui.use('laydate', function() {
					var laydate = layui.laydate;
					//var nowTime=new Date();
					//执行一个laydate实例
					laydate.render({
						elem: '#end_time', //指定元素
						type: 'datetime', //时间日期选择器
						theme: '#0DB6F5', //颜色选取
						calendar: true, //节日显示
						btns: ['confirm'],
						min: -7,
						max: 7, //当前时间
					});
				});
				//JavaScript代码区域
				layui.use('element', function() {
					var element = layui.element;
				});
				//表单js部分
				//Demo
				layui.use('form', function() {
					var form = layui.form;
					//监听提交
					
					form.on('submit(submit)', function(data){
					  alert(data.elem) //被执行事件的元素DOM对象，一般为button对象
					  alert(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
					  alert(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
					  return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
					});
				});
				
				$(function(){
					$('#submit').on('click', function(){
						alert('点击事件');
					});
				});
				
				// 表单使用ajax请求提交
				function leave() {
		            $.ajax({
		            //几个参数需要注意一下
		                type: "POST",//方法类型
		                dataType: "json",//预期服务器返回的数据类型
		                url: "LeaveServlet" ,//url
		                data: $('#leave').serialize(), // 选取表单的id
		                success: function (result) {
		                    console.log(result.msg);//打印服务端返回的数据(调试用)
		                    if(result.code == '200'){
		                    	 $('#msg').html("提交成功");
		                    	 location.href = "leavetest.jsp";
		                    } else if(result.code == '222'){
		                    	 $('#msg').html("请勿重复提交");
		                    } else {
		                    	 $('#msg').html("提交失败");
		                    }
		                },
		                error : function() {
		                    alert("异常！");
		                }
		            });
		        }
				
			</script>
</body>
</html>